<template>
<div class="goods-list">
    <router-link class="goods-item" v-for="item in goodslist" :key="item.id" 
        :to="'/home/goodsdetail/' + item.id" tag="div">
        <img :src="item.img_url" alt="呃呃，图片丢失了。。">
        <h1 class="goods-title">{{ item.title }}</h1>
        <div class="goods-info">
            <p class="price">
                <span class="now">￥{{ item.sell_price }}</span>
                <span class="old">￥{{ item.market_price }}</span>
            </p>
            <p class="sell">
                <span>热卖中</span>
                <span>剩{{ item.stock_quantity }}件</span>
            </p>
        </div>
    </router-link>
    <mt-button type="danger" size="large" @click="getmore">加载更多</mt-button>
</div>
</template>

<script>
import { Toast } from 'mint-ui'
export default {
    data(){
        return {
            goodslist: [],
            pageindex: 1
        }
    },
    created(){
        this.getGoodsList()
    },
    methods: {
        getGoodsList(){  // 获取商品信息
            this.$http.get('api/getgoods?pageindex=' + this.pageindex).then(result => {
                if(result.body.status === 0){
                    var msg = result.body.message
                    if(msg.length === 0){
                        Toast({
                            message: "我也是有底线的。。",
                            position: "bottom",
                            duration: 2000
                        })
                    }else{
                        this.goodslist = this.goodslist.concat(msg)
                    }
                }
            })
        },
        getmore(){   // 点击更多
            this.pageindex++;
            this.getGoodsList()
        }
    }
}
</script>

<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 5px;
    .goods-item{
        width: 49%;
        background-color: #fff;
        border: 1px solid #ccc;
        box-shadow: 0 0 4px #999;
        margin: 5px 0;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        font-weight: bold;
        min-height: 253px;
        img{
            width: 100%;
            min-height: 137px;
        }
        h1{
            font-size: 14px;
            color: #333;
        }
        .goods-info{
            padding: 5px 0;
            background-color: rgba(0, 0, 0, 0.1);
            p{
                margin-bottom: 0;
            }
            .price{
                .now{
                    color: red;
                }
                .old{
                    font-weight: normal;
                    text-decoration: line-through;
                }
            }
            .sell{
                display: flex;
                font-weight: normal;
                justify-content: space-between;
            }
        }
    }
}
</style>